package com.ss.android.account.activity.mobile;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.util.Base64;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ss.android.account.bb;
import com.ss.android.account.customview.a.e;
import com.ss.android.article.browser.R;
import com.ss.android.common.dialog.AlertDialog;

public final class a extends DialogFragment {
    public int e;
    EditText a;
    TextView b;
    View c;
    a$a d;
    private ImageView f;
    private View g;
    private String h;
    public a() {

    }

    public static a a(String arg3, int arg4, com.ss.android.account.activity.mobile.a.a$a arg5) {
        a v0 = new a();
        Bundle v1 = new Bundle();
        v1.putString("captcha_data", arg3);
        v1.putInt("captcha_scenario", arg4);
        v0.setArguments(v1);
        v0.d = arg5;
        return v0;
    }

    public final void a(String arg7, String arg8, int arg9) {
        int v5 = View.GONE;
        this.e = arg9;
        this.h = arg7;
        if (this.f != null) {
            ViewGroup.LayoutParams v1 = this.f.getLayoutParams();
            try {
                byte[] v0_1 = Base64.decode(this.h, 1);
                Bitmap v0_2 = BitmapFactory.decodeByteArray(v0_1, 0, v0_1.length);
                this.f.setImageBitmap(v0_2);
                if (v0_2.getWidth() > 0 && v0_2.getHeight() > 0) {
                    v1.width = this.getResources().getDimensionPixelSize(R.dimen.c7);
                    v1.height = v1.width * v0_2.getHeight() / v0_2.getWidth();
                } else {
                    v1.height = 0;
                }
            } catch (Exception v0) {
                v0.printStackTrace();
                v1.height = 0;
            }
        }

        if (TextUtils.isEmpty(((CharSequence) arg8))) {
            this.c.setVisibility(View.VISIBLE);
            this.b.setVisibility(v5);
        } else {
            this.c.setVisibility(v5);
            this.b.setVisibility(View.VISIBLE);
            this.b.setText(((CharSequence) arg8));
        }
    }

    public final void onCreate(Bundle arg3) {
        super.onCreate(arg3);
        Bundle v0 = this.getArguments();
        this.h = v0.getString("captcha_data");
        this.e = v0.getInt("captcha_scenario");
    }

    @SuppressLint(value = {"InflateParams"})
    public final Dialog onCreateDialog(Bundle arg7) {
        AlertDialog.Builder v1 = bb.a().a(this.getActivity());
        View v2 = this.getActivity().getLayoutInflater().inflate(com.ss.android.article.browser.R.layout.input_captcha_dialog, null);
        this.f = v2.findViewById(com.ss.android.article.browser.R.id.captcha);
        this.g = v2.findViewById(com.ss.android.article.browser.R.id.change_btn);
        this.a = v2.findViewById(com.ss.android.article.browser.R.id.captcha_edit);
        this.b = v2.findViewById(com.ss.android.article.browser.R.id.error);
        this.c = v2.findViewById(com.ss.android.article.browser.R.id.prompt);
        this.a(this.h, "", this.e);
        this.g.setOnClickListener(new com.ss.android.account.activity.mobile.b(this));
        v1.setCustomTitle(v2);
        v1.setPositiveButton(com.ss.android.article.browser.R.string.label_ok, null);
        v1.setNegativeButton(com.ss.android.article.browser.R.string.cancel, null);
        return v1.create();
    }

    public final void onDismiss(DialogInterface arg3) {
        if (this.b != null) {
            this.b.setVisibility(View.INVISIBLE);
        }

        super.onDismiss(arg3);
    }

    public final void onStart() {
        super.onStart();
        Dialog v0 = this.getDialog();
        if (v0 != null) {
            ((AlertDialog) v0).mAlert.mButtonPositive.setOnClickListener(new c(this));
        }
    }

    public static final class a$a {
        public final e c;
        public final com.ss.android.account.customview.a.e.a a;
        public final int b;

        public a$a(e arg1, com.ss.android.account.customview.a.e.a arg2, int arg3) {
            this.c = arg1;
            this.a = arg2;
            this.b = arg3;

        }
    }
}

